﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Collections_Arrays_training_9_4_2017
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] monthsOfYear = { "Январь", "Февраль", "Марть", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь" };
            string[] newSeason = new string[14];

            monthsOfYear.CopyTo(newSeason, 1);

            foreach (var item in newSeason)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine();

            //////////////////////////////////////////////////////////////

            string[] season3 = new string[6];
            Array.Copy(monthsOfYear, season3, 6);
            foreach (var item in season3)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();

            //////////////////////////////////////////////////////////////

            Array.Sort(monthsOfYear);
            Array.Reverse(monthsOfYear);
            foreach (var item in monthsOfYear)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine();

            //////////////////////////////////////////////////////////////

            Console.WriteLine(Array.IndexOf(monthsOfYear, "Ноябрь"));
            Console.WriteLine();

            //////////////////////////////////////////////////////////////

            MyComparer mycomparer = new MyComparer();
            Array.Sort(monthsOfYear, mycomparer);

            foreach (var item in monthsOfYear)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine();

            //////////////////////////////////////////////////////////////

            string[] letterAstartin = Array.FindAll(monthsOfYear, x => x[0] == 'А');

            foreach (var item in letterAstartin)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine();

            //////////////////////////////////////////////////////////////


            Car[] cars = new Car[]
            {
                new Car("Mercedes", 10000, "Blue", 1990, "S600"),
                new Car("Audi", 20000, "Red", 1992, "A3"),
                new Car("Renault", 5000, "Black", 1998, "Duster"),
                new Car("BMW", 40000, "Black", 2000, "X5"),
                new Car("BMW", 45000, "Red", 2003, "X6"),
                new Car("Audi", 35000, "silver", 1998, "A3"),
                new Car("BMW", 33000, "white", 2003, "A3"),
                new Car("Mazda", 22000, "white", 2004, "6"),
                new Car("Mazda", 24000, "blue", 2004, "3")
            };

            Car[] expensiveCars = Array.FindAll(cars, x => x.cost > 30000);
            foreach (var item in expensiveCars)
            {
                Console.WriteLine(item.ToString());
            }
            Console.WriteLine();

            Car[] specificCars = Array.FindAll(cars, n => n.brand == "Audi" || n.brand == "BMW");
            foreach (var item in specificCars)
            {
                Console.WriteLine(item.ToString());
            }
            Console.WriteLine();

            Car[] AudiA3 = Array.FindAll(cars, m => (m.brand == "Audi" && m.model == "A3"));
            foreach (var item in AudiA3)
            {
                Console.WriteLine(item.ToString());
            }
            Console.WriteLine();

            Car[] carList = Array.FindAll(cars, m => ((m.color == "Red") && (m.cost >= 15000) && (m.cost<=50000) && (m.brand!="Audi")));
            foreach (var item in carList)
            {
                Console.WriteLine(item.ToString());
            }
            Console.WriteLine();
        }


        class MyComparer : IComparer<string>
        {
            public int Compare(string x, string y)
            {
                if (x[x.Length - 2] > y[y.Length - 2])
                {
                    return 1;
                }
                else if (x[x.Length - 2] == y[y.Length - 2])
                {
                    return 0;
                }
                else
                {
                    return -1;
                }
            }
        }


        class Car
        {

            public string brand;
            public int cost;
            public string color;
            public int year;
            public string model;
            StringBuilder builder = new StringBuilder();

            public Car(string brand, int cost, string color, int year, string model)
            {
                this.brand = brand;
                this.cost = cost;
                this.color = color;
                this.year = year;
                this.model = model;
            }

            //public override string ToString()
            //{
            //    return this.brand + " " + this.cost + " " + this.color + " " + this.year + " " + this.model;
            //}

            public override string ToString()
            {
                builder.AppendFormat("{0} {1} {2} {3} {4}", brand, cost, color, year, model);
                string carsInfo = builder.ToString();
                return carsInfo;
            }




        }

    }
}
